package com.shun.gateway.exception;

import com.shun.common.R;
import com.shun.gateway.msg.GatewayErrorCode;
import lombok.Getter;

/**
 * Api异常处理
 * @author clever
 * @since 2021-09-18
 */
public class ApiGatewayException extends Exception{

    //返回码
    @Getter
    private String code;

    //返回异常说明
    @Getter
    private String message;

    public ApiGatewayException(){
        super();
    }

    public ApiGatewayException(String message){
         super(message);
    }

    public ApiGatewayException(String code,String message){
        super(message);
        this.code = code;
        this.message = message;
    }

    public ApiGatewayException(GatewayErrorCode errorCode){
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    /**
     * 获得异常信息
     * @return
     */
    public R getError(){
        return new R().setCode(this.code).setMsg(this.message);
    }
}
